﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using JobSiteStarterKit.DAL;

public partial class verify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((Request.Params["identify"] != null) && (Request.Params["role"] != null))
        {
            using (DBAccess db = new DBAccess())
            {
                string user_role = Request.Params["role"];
                
                db.CommandText = "JobsDb_RegisterMember";
                SqlParameter userid = new SqlParameter("@userid", SqlDbType.VarChar, 500);
                userid.Value = Request.Params["identify"].Trim();
                SqlParameter userrole = new SqlParameter("@userrole", SqlDbType.Int);
                userrole.Value = Convert.ToInt32(user_role);
                SqlParameter Status = new SqlParameter("@Status", SqlDbType.Int);
                Status.Direction = ParameterDirection.Output;
                SqlParameter username = new SqlParameter("@username", SqlDbType.VarChar,50);
                username.Direction = ParameterDirection.Output;

                SqlParameterCollection col = (SqlParameterCollection ) db.Parameters;
                col.AddRange(new SqlParameter[] { userid, username, userrole, Status });
                db.ExecuteNonQuery();
                int iStatus = Convert.ToInt32(Status.Value);
                string user_name = Convert.ToString( username.Value);
                if (iStatus == 1)
                {
                    //writecodefor success message
                    msg.InnerText = "Your Registraion is accepted. Please click on continue to login <br /> Your account. Thank you...";
                    FormsAuthentication.SetAuthCookie(user_name, false);
                    if (user_role == "1")
                        Response.Redirect("employer/default.aspx");
                    else if (user_role == "2")
                        Response.Redirect("jobseeker/default.aspx");
                }
                else
                {
                    // write code for failure
                    msg.InnerText = " Sorry! due to some technical problem we can't access your record. <br /> Please try again...";


                }
            }

        }
    }
}
